package org.example.struct.array;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author liyishan
 * @date 2023/12/25 10:01
 * @apiNote
 */

public class Test00575DistributeCandies {

    public static int distributeCandies(int[] candyType) {
        Map<Integer,Integer> map = new HashMap<>();
        int n = candyType.length;
        for (int i = 0; i < n; i++) {
            map.put(candyType[i],map.getOrDefault(candyType[i],0)+1);
        }
        return Math.min(n/2,map.size());
    }

    public int distributeCandies1(int[] candyType) {
        Set<Integer> set = new HashSet<>();
        for(int num : candyType){
            set.add(num);
        }
        return Math.min(candyType.length/2,set.size());
    }
}
